package com.ajzhang.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.ajzhang.bean.UserInfo;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class Filter extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		Object action = actionInvocation.getAction();
		UserInfo userInfo = (UserInfo) request.getSession().getAttribute("UserInfo");
		if(action instanceof com.ajzhang.action.UserInfoAction || userInfo != null){
			return actionInvocation.invoke();
		}
		return "login";
	}

}
